package com.qhg.saas_server.controller;

import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.Supplier;
import com.qhg.saas_server.pojo.dto.SupplierDto;
import com.qhg.saas_server.service.impl.SupplierServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/Supplier")
public class SupplierController {

    @Autowired
    SupplierServiceImpl supplierService;

    /*通过供货商名称和联系人员分页模糊查询供货商*/
    @PostMapping("/SelectAll")
    public Result SelectAll(Integer pageNum,Integer pageSize,String supName, String comploName){
        PageInfo pageInfo = supplierService.SelectAll(pageNum, pageSize, supName, comploName);
        return Result.success(pageInfo);
    }
    /*通过ID搜索供货商*/
    @GetMapping("/SelectById")
    public Result SelectById(Integer supId){
        SupplierDto supplierDto = supplierService.SelectById(supId);
        return Result.success(supplierDto);
    }
    /*插入供货商*/
    @PostMapping("/InsertSupplier")
    public Result InsertSupplier(@RequestBody Supplier supplier){
        supplierService.InsertSupplier(supplier);
        return Result.buildSuccess();
    }
    /*修改供货商信息*/
    @PostMapping("/UpdateSupplier")
    public Result UpdateSupplier(@RequestBody Supplier supplier){
        supplierService.UpdateSupplier(supplier);
        return Result.buildSuccess();
    }
    /*通过ID删除供货商信息*/
    @GetMapping("/DeleteSupplier")
    public Result DeleteSupplier( Integer supId){
        supplierService.DeleteSupplier(supId);
        return Result.buildSuccess();
    }
}
